package org.qiyu.live.im.core.server.bio;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-10-05
 * Time: 23:27
 */
public class BioServer {
    public static void main(String[] args) {
        try {
            // 创建服务端socket
            ServerSocket serverSocket = new ServerSocket();
            // 绑定9090端口,监听9090端口
            serverSocket.bind(new InetSocketAddress(9090));
            // 阻塞获取数据
            System.out.println("server开始监听9090端口");
            Socket socket = serverSocket.accept();// 这里是BIO会进行阻塞
            // 不断地获取数据
            while(true) {
                // 我们要把数据收进来-->输入流
                InputStream inputStream = socket.getInputStream();
                byte[] bytes = new byte[10];
                inputStream.read(bytes);
                System.out.println("服务端接收数据为 : " + new String(bytes));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}